#comments-start - More Info Dialog
[SCRIPT NAME]Move Files To Folder
Description:
    - Moves file(s) from the source location to the target desitionation.

Arguments:
    - Arg1: Folder to move (Required) - e.g. C:\MyFiles
    - Arg2: Destination folder to move to (Required) - e.g. C:\MyFiles2
    - Arg3: Overwrite existing files flag [Optional]
        - Options: (Combining values is allowed. e.g. 9 would give you functionality from both 1 & 8)
            - 0 = Do not overwrite existing files (Default)
            - 1 = Overwrite existing files
            - 8 = Create destination directory structure if it doesn't exist.
    - Arg4: Rename moved folder [Optional]
        - Default is same name as source file
        - Examples: (Assumes source folder name is: C:\MyFiles and moving to same directory but renaming)
            - Specifying Old_* results in destination name: C:\Old_MyFiles
            - Specifying *_Old results in:  C:\MyFiles_Old
#comments-end - More Info Dialog
#include <Include\WinClickPro.au3>
#include <Include\File.au3>
#include <Include\Misc.au3>

Func Main()
	Local $sSourceFolderPath = ""
	Local $sTargetFolderPath = ""
	Local $sOverwriteFlag = 0 ; Default is to not overwrite
	Local $sNewFolderName = "*" ; Default is same name as source file

	;
	; This script has 2 required argument and 3 optional.
	;
	If $CmdLine[0]  < 2 Then
		_DisplayErrorAndExit("Invalid argument count detected!" & @LF & "Count: " & $CmdLine[0])
	EndIf

	$sSourceFolderPath = $CmdLine[1];
	$sTargetFolderPath = $CmdLine[2];

	;
	; Did the user specify an optional filter?
	;
	If $CmdLine[0] > 2 Then
		$sOverwriteFlag = $CmdLine[3]
		If $sOverwriteFlag == "" Then
			$sOverwriteFlag = 0 ; User passed in a blank Arg, reset to default.
		ElseIf $sOverwriteFlag <> 0 And $sOverwriteFlag <> 1 And $sOverwriteFlag <> 8 And $sOverwriteFlag <> 9 Then
			_DisplayErrorAndExit("Overwrite flag is unexpected value!" & @LF & "Value: " & $sOverwriteFlag)
		EndIf
	EndIf

	;
	; Did the user specify the optional file name?
	;
	If $CmdLine[0] > 3 Then
		$sNewFolderName = $CmdLine[4]
		If $sNewFolderName == "" Then
			$sNewFolderName = "*" ; User passed in a blank Arg, reset to default.
		EndIf
	EndIf

	;
	; The source folder must exist. If not, inform user.
	;
	If Not FileExists($sSourceFolderPath) Then
		_DisplayErrorAndExit("Folder does not exist!" & @LF & "Folder: " & $sSourceFolderPath)
	EndIf

	;
	; The destination folder must exist if they aren't creating it on the fly.
	;
	If Not FileExists($sTargetFolderPath) And $sOverwriteFlag < 8 Then
		_DisplayErrorAndExit("Folder does not exist!" & @LF & "Folder: " & $sTargetFolderPath)
	EndIf

	;
	; Make sure the source folder path does not have a trailing \ (per documentation)
	;
	If StringRight($sSourceFolderPath, 1) == "\" Then
		$sSourceFolderPath = StringLeft($sSourceFolderPath, StringLen($sSourceFolderPath)-1)
	EndIf

	;
	; Make sure the folder path does not have a trailing \ if the user isn't renaming.
	;
	If StringRight($sTargetFolderPath, 1) == "\" Then
		$sTargetFolderPath = StringLeft($sTargetFolderPath, StringLen($sTargetFolderPath)-1)
	EndIf

	If $sNewFolderName <> "" Then
		$sTargetFolderPath = $sTargetFolderPath & "\" & $sNewFolderName
	EndIf

	DirMove($sSourceFolderPath, $sTargetFolderPath, $sOverwriteFlag)
EndFunc

Main()
Exit @error